package edu.szte.ovrt.datahandler.model;

import java.util.LinkedList;
import java.util.List;

public class Document extends ModelBase {
	private final List<Section> m_sections = new LinkedList<Section>();

	/*
	 * public Document(final String filename) { m_filename = filename; } private String m_filename; public String getFilename() {
	 * return m_filename; } public void setFilename(final String filename) { m_filename = filename; }
	 */

	public List<Section> getSections() {
		return m_sections;
	}

	@Override
	public String getName() {
		return null;
		// return m_filename.substring(m_filename.lastIndexOf('\\'));
	}

	public void addSection(final Section section) {
		m_sections.add(section);
	}

	public Section newSection(final String title) {
		final Section s = new Section(this, title);
		addSection(s);
		return s;
	}

	@Override
	public boolean equals(final Object obj) {
		if (obj == null || !(obj instanceof Document)) { return false; }
		final Document other = (Document) obj;
		return m_sections.equals(other.m_sections);
	}

	@Override
	public int hashCode() {
		int hashCode = Document.class.getName().hashCode();
		for (final Section section : m_sections) {
			hashCode ^= section.hashCode();
		}
		return hashCode;
	}

	@Override
	public String toString() {
		return String.format("Document ({0})", getSections().size());
	}
}
